package com.fcscs.cservice.client.main.configuration.inroomdining;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.fcscs.core.gwt.common.CoreConstants;
import com.fcscs.core.gwt.common.FormSubmitListener;
import com.fcscs.core.gwt.common.ui.BaseFormDialog;
import com.fcscs.core.gwt.common.ui.FcsFields.EasyClearCombobox;
import com.fcscs.core.gwt.common.ui.FcsFields.FormButton;
import com.fcscs.core.gwt.common.ui.FcsFormPanel;
import com.fcscs.cservice.client.common.CServiceConstants;
import com.fcscs.cservice.client.common.model.configuration.inroomdining.ChargeCategory;
import com.fcscs.cservice.client.common.model.configuration.inroomdining.ChargeCategoryModelData;

public class ChargeCategoryDialog extends BaseFormDialog<ChargeCategory> {

	private static ChargeCategoryDialog INSTANCE;
	private MyFormPanel myFormPanel;
	private HorizontalPanel hp1;
	private LayoutContainer lc1;
	private TextField<String> chargeField;
	private TextField<String> chargeField1;
	private TextField<String> chargeField2;
	private FieldSet fieldSet1;
	private HorizontalPanel hp2;
	private LayoutContainer lc2;
	private HorizontalPanel hp3;
	private LayoutContainer lc3;
	private FormButton saveBtn;
	private FormButton cancelBtn;
	private HorizontalPanel hp4;
	private LayoutContainer lc4;
	private HorizontalPanel hp5;
	private LayoutContainer lc5;
	private HorizontalPanel hp6;
	private LayoutContainer lc6;
	private EasyClearCombobox<ChargeCategoryModelData> chargeByCombox;
	private EasyClearCombobox<ChargeCategoryModelData> chargeByCombox1;
	private EasyClearCombobox<ChargeCategoryModelData> chargeByCombox2;
	private EasyClearCombobox<ChargeCategoryModelData> chargeByCombox3;
	private TextField<String> valueField;
	private TextField<String> valueField1;
	private TextField<String> valueField2;
	private TextField<String> valueField3;
	private boolean isAdd;
	private VerticalPanel vp;
	private EasyClearCombobox<ChargeCategoryModelData> nameCombox;
	private EasyClearCombobox<ChargeCategoryModelData> nameCombox1;
	private EasyClearCombobox<ChargeCategoryModelData> nameCombox2;
	private EasyClearCombobox<ChargeCategoryModelData> nameCombox3;
	private ListStore<ChargeCategoryModelData> chargeTypeStore;
	
	public static ChargeCategoryDialog getInstance(boolean add) {

		if (null == INSTANCE) {
			INSTANCE = new ChargeCategoryDialog();
		}
		INSTANCE.isAdd = add;
		INSTANCE.setHeader();
		return INSTANCE;
	}

	public void setHeader(){
		if (isAdd) {
			INSTANCE.setHeading(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.add(),
					CServiceConstants.CSERVICE_CONSTANTS.chargeCategory()));
		}else {
//			INSTANCE.updatepanel();
			INSTANCE.setHeading(CoreConstants.CORE_MESSAGES.operation(CoreConstants.CORE_CONSTANTS.edit(),
					CServiceConstants.CSERVICE_CONSTANTS.chargeCategory()));
		}
	}
	
	private ChargeCategoryDialog() {
		myFormPanel = new MyFormPanel(null);
		add(myFormPanel);
		setSize(700, 280);
	}

	public class MyFormPanel extends FcsFormPanel<ChargeCategory> {

		protected MyFormPanel(FormSubmitListener<ChargeCategory> l) {
			super(l);
			setHeaderVisible(false);

			if (null == vp) {
				vp = new VerticalPanel();
				vp.setSpacing(5);
				vp.setId("ChargeCategoryDialog_vp");

				hp1 = new HorizontalPanel();
				hp1.setId("ChargeCategoryDialog_hp1");
				vp.add(hp1);

				lc1 = new LayoutContainer();
				lc1.setId("ChargeCategoryDialog_lc1");
				lc1.setLayout(new ColumnLayout());
				hp1.add(lc1);

				Label chargeLabel = new Label(CServiceConstants.CSERVICE_CONSTANTS.chargeCategory()
						+ CServiceConstants.FIELD_SEP);
				chargeLabel.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "15px");
				chargeLabel.setId("ChargeCategoryDialog_chargeLabel");
				lc1.add(chargeLabel, new ColumnData(120));

				chargeField = new TextField<String>();
				chargeField.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.simplifiedChinese());
				chargeField.setId("ChargeCategoryDialog_chargeField");
				lc1.add(chargeField, new ColumnData(160));

				chargeField1 = new TextField<String>();
				chargeField1.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.triditionalChinese());
				chargeField1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				chargeField1.setId("ChargeCategoryDialog_chargeField1");
				lc1.add(chargeField1, new ColumnData(160));

				chargeField2 = new TextField<String>();
				chargeField2.setEmptyText(CServiceConstants.CSERVICE_CONSTANTS.simplifiedChinese());
				chargeField2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				chargeField2.setId("ChargeCategoryDialog_chargeField2");
				lc1.add(chargeField2, new ColumnData(160));

				fieldSet1 = new FieldSet();
				fieldSet1.setBorders(false);
				fieldSet1.setId("ChargeCategoryDialog_fieldSet1");
				fieldSet1.setSize(830, 120);
				vp.add(fieldSet1);

				VerticalPanel vp1 = new VerticalPanel();
				vp1.setSpacing(5);
				vp1.setId("ChargeCategoryDialog_vp1");
				fieldSet1.add(vp1);

				hp2 = new HorizontalPanel();
				hp2.setId("ChargeCategoryDialog_hp2");
				vp1.add(hp2);

				lc2 = new LayoutContainer();
				lc2.setId("ChargeCategoryDialog_lc2");
				lc2.setLayout(new ColumnLayout());
				hp2.add(lc2);
				
				Label nameLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.nameCodeOnlyEng() + CoreConstants.REQURIED_FIELD_LABEL);
				nameLab.setId("ChargeCategoryDialog_nameLab");
				lc2.add(nameLab, new ColumnData(200));
				
				Label chargeByLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.chargeBy()+CoreConstants.REQURIED_FIELD_LABEL);
				chargeByLab.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				chargeByLab.setId("ChargeCategoryDialog_chargeByLab");
				lc2.add(chargeByLab, new ColumnData(200));
				
				Label valueLab = new Label(CServiceConstants.CSERVICE_CONSTANTS.value()+CoreConstants.REQURIED_FIELD_LABEL);
				valueLab.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				valueLab.setId("ChargeCategoryDialog_valueLab");
				lc2.add(valueLab, new ColumnData(200));
				
				
				hp3 = new HorizontalPanel();
				hp3.setId("ChargeCategoryDialog_hp3");
				vp1.add(hp3);

				lc3 = new LayoutContainer();
				lc3.setId("ChargeCategoryDialog_lc3");
				lc3.setLayout(new ColumnLayout());
				hp3.add(lc3);
				
				nameCombox = new EasyClearCombobox<ChargeCategoryModelData>();
				nameCombox.setId("ChargeCategoryDialog_nameCombox");
				chargeTypeStore = new ListStore<ChargeCategoryModelData>();
				nameCombox.setStore(chargeTypeStore);
				nameCombox.setDisplayField(CoreConstants.FULLTNAME);
				nameCombox.setTriggerAction(TriggerAction.ALL);
				nameCombox.setForceSelection(true);
				lc3.add(nameCombox, new ColumnData(200));
				
				chargeByCombox = new EasyClearCombobox<ChargeCategoryModelData>();
				chargeByCombox.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				chargeByCombox.setId("ChargeCategoryDialog_chargeByCombox");
				chargeTypeStore = new ListStore<ChargeCategoryModelData>();
				chargeByCombox.setStore(chargeTypeStore);
				chargeByCombox.setDisplayField(CoreConstants.FULLTNAME);
				chargeByCombox.setTriggerAction(TriggerAction.ALL);
				chargeByCombox.setForceSelection(true);
				lc3.add(chargeByCombox, new ColumnData(200));
				
				valueField = new TextField<String>();
				valueField.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				valueField.setId("ChargeCategoryDialog_valueField");
				lc3.add(valueField, new ColumnData(200));
				
				hp4 = new HorizontalPanel();
				hp4.setId("ChargeCategoryDialog_hp4");
				vp1.add(hp4);
				
				lc4 = new LayoutContainer();
				lc4.setId("ChargeCategoryDialog_lc4");
				lc4.setLayout(new ColumnLayout());
				hp4.add(lc4);
				
				nameCombox1 = new EasyClearCombobox<ChargeCategoryModelData>();
				nameCombox1.setId("ChargeCategoryDialog_nameCombox1");
				chargeTypeStore = new ListStore<ChargeCategoryModelData>();
				nameCombox1.setStore(chargeTypeStore);
				nameCombox1.setDisplayField(CoreConstants.FULLTNAME);
				nameCombox1.setTriggerAction(TriggerAction.ALL);
				nameCombox1.setForceSelection(true);
				lc4.add(nameCombox1, new ColumnData(200));
				
				chargeByCombox1 = new EasyClearCombobox<ChargeCategoryModelData>();
				chargeByCombox1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				chargeByCombox1.setId("ChargeCategoryDialog_chargeByCombox1");
				chargeTypeStore = new ListStore<ChargeCategoryModelData>();
				chargeByCombox1.setStore(chargeTypeStore);
				chargeByCombox1.setDisplayField(CoreConstants.FULLTNAME);
				chargeByCombox1.setTriggerAction(TriggerAction.ALL);
				chargeByCombox1.setForceSelection(true);
				lc4.add(chargeByCombox1, new ColumnData(200));
				
				valueField1 = new TextField<String>();
				valueField1.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				valueField1.setId("ChargeCategoryDialog_valueField1");
				lc4.add(valueField1, new ColumnData(200));
				
				hp5 = new HorizontalPanel();
				hp5.setId("ChargeCategoryDialog_hp5");
				vp1.add(hp5);
				
				lc5 = new LayoutContainer();
				lc5.setId("ChargeCategoryDialog_lc5");
				lc5.setLayout(new ColumnLayout());
				hp5.add(lc5);
				
				nameCombox2 = new EasyClearCombobox<ChargeCategoryModelData>();
				nameCombox2.setId("ChargeCategoryDialog_nameCombox2");
				chargeTypeStore = new ListStore<ChargeCategoryModelData>();
				nameCombox2.setStore(chargeTypeStore);
				nameCombox2.setDisplayField(CoreConstants.FULLTNAME);
				nameCombox2.setTriggerAction(TriggerAction.ALL);
				nameCombox2.setForceSelection(true);
				lc5.add(nameCombox2, new ColumnData(200));
				
				chargeByCombox2 = new EasyClearCombobox<ChargeCategoryModelData>();
				chargeByCombox2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				chargeByCombox2.setId("ChargeCategoryDialog_chargeByCombox2");
				chargeTypeStore = new ListStore<ChargeCategoryModelData>();
				chargeByCombox2.setStore(chargeTypeStore);
				chargeByCombox2.setDisplayField(CoreConstants.FULLTNAME);
				chargeByCombox2.setTriggerAction(TriggerAction.ALL);
				chargeByCombox2.setForceSelection(true);
				lc5.add(chargeByCombox2, new ColumnData(200));
				
				valueField2 = new TextField<String>();
				valueField2.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				valueField2.setId("ChargeCategoryDialog_valueField2");
				lc5.add(valueField2, new ColumnData(200));
				
				hp6 = new HorizontalPanel();
				hp6.setId("ChargeCategoryDialog_hp6");
				vp1.add(hp6);
				
				lc6 = new LayoutContainer();
				lc6.setId("ChargeCategoryDialog_lc6");
				lc6.setLayout(new ColumnLayout());
				hp6.add(lc6);
				
				nameCombox3 = new EasyClearCombobox<ChargeCategoryModelData>();
				nameCombox3.setId("ChargeCategoryDialog_nameCombox2");
				chargeTypeStore = new ListStore<ChargeCategoryModelData>();
				nameCombox3.setStore(chargeTypeStore);
				nameCombox3.setDisplayField(CoreConstants.FULLTNAME);
				nameCombox3.setTriggerAction(TriggerAction.ALL);
				nameCombox3.setForceSelection(true);
				lc6.add(nameCombox3, new ColumnData(200));
				
				chargeByCombox3 = new EasyClearCombobox<ChargeCategoryModelData>();
				chargeByCombox3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				chargeByCombox3.setId("ChargeCategoryDialog_chargeByCombox2");
				chargeTypeStore = new ListStore<ChargeCategoryModelData>();
				chargeByCombox3.setStore(chargeTypeStore);
				chargeByCombox3.setDisplayField(CoreConstants.FULLTNAME);
				chargeByCombox3.setTriggerAction(TriggerAction.ALL);
				chargeByCombox3.setForceSelection(true);
				lc6.add(chargeByCombox3, new ColumnData(200));
				
				valueField3 = new TextField<String>();
				valueField3.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "10px");
				valueField3.setId("ChargeCategoryDialog_valueField2");
				lc6.add(valueField3, new ColumnData(200));
				
				saveBtn = new FormButton(CoreConstants.CORE_CONSTANTS.save());
				saveBtn.setId("ChargeCategoryDialog_saveBtn_Id");
				getButtonBar().add(saveBtn);

				cancelBtn = new FormButton(CoreConstants.CORE_CONSTANTS.cancel());
				cancelBtn.setId("ChargeCategoryDialog_cancelBtn_Id");
				cancelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {

					@Override
					public void componentSelected(ButtonEvent ce) {
						ChargeCategoryDialog.this.hide();
						cancelBtn.removeStyleName(CoreConstants.CSS_FORM_BUTTON_FOCUS);
					}
				});
				getButtonBar().add(cancelBtn);

				add(vp);
			}
		}

		@Override
		public void setFocus() {

		}

		@Override
		public void updateForm(ChargeCategory entity) {
			chargeField.setValue(entity.getChargeCategory());
			nameCombox.setRawValue("name(t001)");
			chargeByCombox.setRawValue("fixed");
			valueField.setValue("10");
		}
		
		@Override
		public void populateEntity(ChargeCategory entity) {
			
		}

	}

	@Override
	public void hide() {
		super.hide();
	}

	@Override
	protected FcsFormPanel<ChargeCategory> getFormPanel() {
		return myFormPanel;
	}
}
